package adapters;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.newxlmedical.ComboModifyAndAddActivity;
import com.example.administrator.newxlmedical.R;

import java.util.List;

import beans.ComboBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import custom.BaseRecyclerAdapter;
import dialogs.ComboSetDeleteDialog;
import netframe.GetRetrofit;
import netframe.NetAddress;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import utils.ActivityUtil;
import utils.ToastUtil;

/**
 * Created by Administrator on 2018/11/10.
 */

public class ComboSetAdapter extends BaseRecyclerAdapter<ComboSetAdapter.ComboSetViewHolder> {
    private Context mContext;
    private ComboSetListener listener;
    private List<ComboBean.DataBean> list;
    public ComboSetAdapter(Context context,ComboSetListener listener,List<ComboBean.DataBean> list) {
        mContext = context;
        this.listener = listener;
        this.list = list;
    }

    @Override
    public ComboSetAdapter.ComboSetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.adapter_combo_set, parent, false);
        ComboSetViewHolder viewHolder = new ComboSetViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ComboSetAdapter.ComboSetViewHolder viewHolder, final int position) {
        final ComboBean.DataBean dataBean = list.get(position);
        viewHolder.tvName.setText(dataBean.getPackageName());
        viewHolder.tvSpecification.setText(String.valueOf(dataBean.getGoodsCount()));
        if (dataBean.getSubTime() != null){
            viewHolder.tvSuppier.setText(dataBean.getSubTime().substring(0,10));
        }

        if (position % 2 == 0) {
            viewHolder.llAdapter.setBackgroundColor(mContext.getResources().getColor(R.color.partLineBackground));
        } else {
            viewHolder.llAdapter.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }

        // 修改
        viewHolder.tvModify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.modify(position);
            }
        });

        // 删除
        viewHolder.tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.delete(dataBean,position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ComboSetViewHolder extends BaseRecyclerAdapter.BaseViewHolder {
        @BindView(R.id.tv_search_name)
        TextView tvName;
        @BindView(R.id.tv_search_specification)
        TextView tvSpecification;
        @BindView(R.id.tv_search_suppier)
        TextView tvSuppier;
        @BindView(R.id.tv_search_modify)
        TextView tvModify;
        @BindView(R.id.tv_search_delete)
        TextView tvDelete;
        @BindView(R.id.ll_search_adapter)
        LinearLayout llAdapter;

        ComboSetViewHolder (View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface ComboSetListener {
        void modify(int position);
        void delete(ComboBean.DataBean bean,int position);
    }
}
